/*
 * FrmAddCustomer.java
 *
 * Created on Sep 26, 2011, 5:52:55 AM
 */
package piusys.customers;

import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;
import piusys.kernel.Utilities;

/**
 *
 * @author mrogers
 */
public class FrmEditCustomer extends javax.swing.JInternalFrame
{

    static final Logger logger = Logger.getLogger(FrmEditCustomer.class.getName());
    static String validationText = "";

    /** Creates new form FrmAddCustomer */
    public FrmEditCustomer()
    {
        initComponents();
        populateLists();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        customerTabbedPane = new javax.swing.JTabbedPane();
        searchPanel = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        lblSearch = new javax.swing.JLabel();
        txtSearch = new javax.swing.JTextField();
        cmdSearch = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        customerTable = new javax.swing.JTable();
        generalPanel = new javax.swing.JPanel();
        lblName = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        lblPriContact = new javax.swing.JLabel();
        txtContact1 = new javax.swing.JTextField();
        lblSecContact = new javax.swing.JLabel();
        txtContact2 = new javax.swing.JTextField();
        cmdCancel = new javax.swing.JButton();
        cmdNext = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        lblID = new javax.swing.JLabel();
        txtID = new javax.swing.JTextField();
        addressPanel = new javax.swing.JPanel();
        lblAddress = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAddress = new javax.swing.JTextArea();
        cmdNext2 = new javax.swing.JButton();
        cmdCancel2 = new javax.swing.JButton();
        txtEmail = new javax.swing.JTextField();
        lblEmail = new javax.swing.JLabel();
        telephonePanel = new javax.swing.JPanel();
        lblPrimaryPhone = new javax.swing.JLabel();
        txtPhone1 = new javax.swing.JTextField();
        lblPhone2 = new javax.swing.JLabel();
        txtPhone2 = new javax.swing.JTextField();
        cmdCancel3 = new javax.swing.JButton();
        cmdNext3 = new javax.swing.JButton();
        lblFax = new javax.swing.JLabel();
        txtFax = new javax.swing.JTextField();
        NotesPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtNotes = new javax.swing.JTextArea();
        lblNotes = new javax.swing.JLabel();
        cmbSave = new javax.swing.JButton();
        cmdCancel4 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(piusys.PIUSYSApp.class).getContext().getResourceMap(FrmEditCustomer.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N

        customerTabbedPane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        customerTabbedPane.setName("customerTabbedPane"); // NOI18N

        searchPanel.setName("searchPanel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(piusys.PIUSYSApp.class).getContext().getActionMap(FrmEditCustomer.class, this);
        jButton2.setAction(actionMap.get("cancel")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setAction(actionMap.get("next")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        lblSearch.setText(resourceMap.getString("lblSearch.text")); // NOI18N
        lblSearch.setName("lblSearch"); // NOI18N

        txtSearch.setText(resourceMap.getString("txtSearch.text")); // NOI18N
        txtSearch.setName("txtSearch"); // NOI18N
        txtSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtSearchKeyPressed(evt);
            }
        });

        cmdSearch.setAction(actionMap.get("search")); // NOI18N
        cmdSearch.setText(resourceMap.getString("cmdSearch.text")); // NOI18N
        cmdSearch.setName("cmdSearch"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        customerTable.setAutoCreateRowSorter(true);
        customerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Customer", "Pri. Contact", "Sec. Contact"
            }
        ));
        customerTable.setName("customerTable"); // NOI18N
        customerTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                customerTableMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(customerTable);
        customerTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        customerTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("customerTable.columnModel.title0")); // NOI18N
        customerTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("customerTable.columnModel.title1")); // NOI18N
        customerTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("customerTable.columnModel.title2")); // NOI18N
        customerTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("customerTable.columnModel.title3")); // NOI18N

        javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, searchPanelLayout.createSequentialGroup()
                        .addComponent(lblSearch)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmdSearch))
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)))
                .addContainerGap())
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSearch)
                    .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdSearch))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        customerTabbedPane.addTab(resourceMap.getString("searchPanel.TabConstraints.tabTitle"), resourceMap.getIcon("searchPanel.TabConstraints.tabIcon"), searchPanel); // NOI18N

        generalPanel.setName("generalPanel"); // NOI18N

        lblName.setText(resourceMap.getString("lblName.text")); // NOI18N
        lblName.setName("lblName"); // NOI18N

        txtName.setText(resourceMap.getString("txtName.text")); // NOI18N
        txtName.setName("txtName"); // NOI18N

        lblPriContact.setText(resourceMap.getString("lblPriContact.text")); // NOI18N
        lblPriContact.setName("lblPriContact"); // NOI18N

        txtContact1.setText(resourceMap.getString("txtContact1.text")); // NOI18N
        txtContact1.setName("txtContact1"); // NOI18N

        lblSecContact.setText(resourceMap.getString("lblSecContact.text")); // NOI18N
        lblSecContact.setName("lblSecContact"); // NOI18N

        txtContact2.setText(resourceMap.getString("txtContact2.text")); // NOI18N
        txtContact2.setName("txtContact2"); // NOI18N

        cmdCancel.setAction(actionMap.get("cancel")); // NOI18N
        cmdCancel.setText(resourceMap.getString("cmdCancel.text")); // NOI18N
        cmdCancel.setName("cmdCancel"); // NOI18N

        cmdNext.setAction(actionMap.get("next")); // NOI18N
        cmdNext.setText(resourceMap.getString("cmdNext.text")); // NOI18N
        cmdNext.setName("cmdNext"); // NOI18N

        jButton1.setAction(actionMap.get("resetForm")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        lblID.setText(resourceMap.getString("lblID.text")); // NOI18N
        lblID.setName("lblID"); // NOI18N

        txtID.setEditable(false);
        txtID.setText(resourceMap.getString("txtID.text")); // NOI18N
        txtID.setName("txtID"); // NOI18N

        javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
        generalPanel.setLayout(generalPanelLayout);
        generalPanelLayout.setHorizontalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 193, Short.MAX_VALUE)
                        .addComponent(cmdNext)
                        .addGap(18, 18, 18)
                        .addComponent(cmdCancel))
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblName)
                            .addComponent(lblPriContact)
                            .addComponent(lblSecContact)
                            .addComponent(lblID))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtID, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                            .addComponent(txtContact2, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                            .addComponent(txtContact1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                            .addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE))))
                .addContainerGap())
        );
        generalPanelLayout.setVerticalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblID)
                    .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblName)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPriContact)
                    .addComponent(txtContact1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSecContact)
                    .addComponent(txtContact2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 170, Short.MAX_VALUE)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdCancel)
                    .addComponent(cmdNext)
                    .addComponent(jButton1))
                .addContainerGap())
        );

        customerTabbedPane.addTab(resourceMap.getString("generalPanel.TabConstraints.tabTitle"), resourceMap.getIcon("generalPanel.TabConstraints.tabIcon"), generalPanel); // NOI18N

        addressPanel.setName("addressPanel"); // NOI18N

        lblAddress.setText(resourceMap.getString("lblAddress.text")); // NOI18N
        lblAddress.setName("lblAddress"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtAddress.setColumns(20);
        txtAddress.setRows(5);
        txtAddress.setName("txtAddress"); // NOI18N
        jScrollPane1.setViewportView(txtAddress);

        cmdNext2.setAction(actionMap.get("next")); // NOI18N
        cmdNext2.setName("cmdNext2"); // NOI18N

        cmdCancel2.setAction(actionMap.get("cancel")); // NOI18N
        cmdCancel2.setName("cmdCancel2"); // NOI18N

        txtEmail.setText(resourceMap.getString("txtEmail.text")); // NOI18N
        txtEmail.setName("txtEmail"); // NOI18N

        lblEmail.setText(resourceMap.getString("lblEmail.text")); // NOI18N
        lblEmail.setName("lblEmail"); // NOI18N

        javax.swing.GroupLayout addressPanelLayout = new javax.swing.GroupLayout(addressPanel);
        addressPanel.setLayout(addressPanelLayout);
        addressPanelLayout.setHorizontalGroup(
            addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addressPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(addressPanelLayout.createSequentialGroup()
                        .addComponent(cmdNext2)
                        .addGap(18, 18, 18)
                        .addComponent(cmdCancel2))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, addressPanelLayout.createSequentialGroup()
                        .addGroup(addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblEmail))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE))))
                .addContainerGap())
        );
        addressPanelLayout.setVerticalGroup(
            addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addressPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEmail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                .addGroup(addressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdCancel2)
                    .addComponent(cmdNext2))
                .addContainerGap())
        );

        customerTabbedPane.addTab(resourceMap.getString("addressPanel.TabConstraints.tabTitle"), resourceMap.getIcon("addressPanel.TabConstraints.tabIcon"), addressPanel); // NOI18N

        telephonePanel.setName("telephonePanel"); // NOI18N

        lblPrimaryPhone.setText(resourceMap.getString("lblPrimaryPhone.text")); // NOI18N
        lblPrimaryPhone.setName("lblPrimaryPhone"); // NOI18N

        txtPhone1.setText(resourceMap.getString("txtPhone1.text")); // NOI18N
        txtPhone1.setName("txtPhone1"); // NOI18N

        lblPhone2.setText(resourceMap.getString("lblPhone2.text")); // NOI18N
        lblPhone2.setName("lblPhone2"); // NOI18N

        txtPhone2.setText(resourceMap.getString("txtPhone2.text")); // NOI18N
        txtPhone2.setName("txtPhone2"); // NOI18N

        cmdCancel3.setAction(actionMap.get("cancel")); // NOI18N
        cmdCancel3.setName("cmdCancel3"); // NOI18N

        cmdNext3.setAction(actionMap.get("next")); // NOI18N
        cmdNext3.setName("cmdNext3"); // NOI18N

        lblFax.setText(resourceMap.getString("lblFax.text")); // NOI18N
        lblFax.setName("lblFax"); // NOI18N

        txtFax.setText(resourceMap.getString("txtFax.text")); // NOI18N
        txtFax.setName("txtFax"); // NOI18N

        javax.swing.GroupLayout telephonePanelLayout = new javax.swing.GroupLayout(telephonePanel);
        telephonePanel.setLayout(telephonePanelLayout);
        telephonePanelLayout.setHorizontalGroup(
            telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(telephonePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, telephonePanelLayout.createSequentialGroup()
                        .addComponent(cmdNext3)
                        .addGap(18, 18, 18)
                        .addComponent(cmdCancel3))
                    .addGroup(telephonePanelLayout.createSequentialGroup()
                        .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPrimaryPhone)
                            .addComponent(lblPhone2)
                            .addComponent(lblFax))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtFax, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                            .addComponent(txtPhone2, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                            .addComponent(txtPhone1, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE))))
                .addContainerGap())
        );
        telephonePanelLayout.setVerticalGroup(
            telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(telephonePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPrimaryPhone)
                    .addComponent(txtPhone1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPhone2)
                    .addComponent(txtPhone2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFax)
                    .addComponent(txtFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
                .addGroup(telephonePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdCancel3)
                    .addComponent(cmdNext3))
                .addContainerGap())
        );

        customerTabbedPane.addTab(resourceMap.getString("telephonePanel.TabConstraints.tabTitle"), resourceMap.getIcon("telephonePanel.TabConstraints.tabIcon"), telephonePanel); // NOI18N

        NotesPanel.setName("NotesPanel"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        txtNotes.setColumns(20);
        txtNotes.setRows(5);
        txtNotes.setName("txtNotes"); // NOI18N
        jScrollPane2.setViewportView(txtNotes);

        lblNotes.setText(resourceMap.getString("lblNotes.text")); // NOI18N
        lblNotes.setName("lblNotes"); // NOI18N

        cmbSave.setAction(actionMap.get("save")); // NOI18N
        cmbSave.setText(resourceMap.getString("cmbSave.text")); // NOI18N
        cmbSave.setName("cmbSave"); // NOI18N

        cmdCancel4.setAction(actionMap.get("cancel")); // NOI18N
        cmdCancel4.setName("cmdCancel4"); // NOI18N

        javax.swing.GroupLayout NotesPanelLayout = new javax.swing.GroupLayout(NotesPanel);
        NotesPanel.setLayout(NotesPanelLayout);
        NotesPanelLayout.setHorizontalGroup(
            NotesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NotesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NotesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(NotesPanelLayout.createSequentialGroup()
                        .addComponent(lblNotes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, NotesPanelLayout.createSequentialGroup()
                        .addComponent(cmbSave)
                        .addGap(18, 18, 18)
                        .addComponent(cmdCancel4)))
                .addContainerGap())
        );
        NotesPanelLayout.setVerticalGroup(
            NotesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(NotesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(NotesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNotes)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(NotesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdCancel4)
                    .addComponent(cmbSave))
                .addContainerGap())
        );

        customerTabbedPane.addTab(resourceMap.getString("NotesPanel.TabConstraints.tabTitle"), resourceMap.getIcon("NotesPanel.TabConstraints.tabIcon"), NotesPanel); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(customerTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(customerTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtSearchKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txtSearchKeyPressed
    {//GEN-HEADEREND:event_txtSearchKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER)
        {
            search();
        }
    }//GEN-LAST:event_txtSearchKeyPressed

    private void customerTableMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_customerTableMouseClicked
    {//GEN-HEADEREND:event_customerTableMouseClicked
        if (evt.getClickCount() >= 2 && customerTable.getSelectedRow() != -1)
        {
            loadInfo();
        }
    }//GEN-LAST:event_customerTableMouseClicked

    @Action
    public void cancel()
    {
        Utilities.showCancelScreen(this);
    }

    @Action
    public void next()
    {
        customerTabbedPane.setSelectedIndex(customerTabbedPane.getSelectedIndex() + 1);
    }

    @Action
    public void save()
    {

        if (!passedValidation())
        {
            Utilities.showWarningMessage(rootPane, validationText);
            return;
        }

        HashMap<String, String> params = new HashMap<String, String>();
        params.put("custName", txtName.getText().trim());
        params.put("custContact1", txtContact1.getText().trim());
        params.put("custContact2", txtContact2.getText().trim());
        params.put("custAddress", txtAddress.getText().trim());
        params.put("custPhone1", txtPhone1.getText().trim());
        params.put("custPhone2", txtPhone2.getText().trim());
        params.put("custEmail", txtEmail.getText().trim());
        params.put("custFax", txtFax.getText().trim());
        params.put("custNotes", txtNotes.getText().trim());
        boolean saveCustomer = Customer.saveCustomer(params);

        if (saveCustomer)
        {
            String message = "The customer was successfully added to the system.\n"
                    + "Would you like to add another?";
            int response = Utilities.showConfirmDialog(rootPane, message);
            if (response == JOptionPane.YES_OPTION)
            {
                resetForm();
            }
            else
            {
                this.dispose();
            }
        }
        else
        {
            String message = "An error occurred while trying to save the customer.\n"
                    + "Kindly verify your input and try again.";
            Utilities.showErrorMessage(rootPane, message);
        }

    }

    private boolean passedValidation()
    {
        boolean passed = true;
        validationText = "Kindly correct the issues below before proceeding.\n\n";

        String custName = txtName.getText().trim();
        String custContact1 = txtContact1.getText().trim();
//        String custPhone1 = txtPhone1.getText().trim();
//        String custPhone2 = txtPhone2.getText().trim();
//        String custEmail = txtEmail.getText().trim();
//        String custFax = txtFax.getText().trim();
//        String custNotes = txtNotes.getText().trim();

        if (custName.isEmpty())
        {
            validationText += "Name cannot be empty.\n";
            passed = false;
        }

        if (custContact1.isEmpty())
        {
            validationText += "You must have at least one contact person listed.\n";
            passed = false;
        }

        return passed;
    }

    @Action
    public void resetForm()
    {
        remove(customerTabbedPane);
        initComponents();
    }

    private void populateLists()
    {
    }

    private void loadInfo()
    {
        if (customerTable.getSelectedRow() != -1)
        {
            String custID = customerTable.getValueAt(customerTable.getSelectedRow(), 0).toString();
            HashMap<String, String> customerDetails = Customer.getCustomerDetails(custID);
            txtID.setText(custID);
            txtName.setText(customerDetails.get("custName"));
            txtContact1.setText(customerDetails.get("custContact1"));
            txtContact2.setText(customerDetails.get("custContact2"));
            txtAddress.setText(customerDetails.get("custAddress"));
            txtEmail.setText(customerDetails.get("custEmail"));
            txtPhone1.setText(customerDetails.get("custPhone1"));
            txtPhone2.setText(customerDetails.get("custPhone2"));
            txtFax.setText(customerDetails.get("custFax"));
            txtNotes.setText(customerDetails.get("custNotes"));
            next();
        }
    }

    @Action
    public void search()
    {
        String criteria = txtSearch.getText().trim();
        customerTable.setModel(Customer.searchCustomers(criteria));
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel NotesPanel;
    private javax.swing.JPanel addressPanel;
    private javax.swing.JButton cmbSave;
    private javax.swing.JButton cmdCancel;
    private javax.swing.JButton cmdCancel2;
    private javax.swing.JButton cmdCancel3;
    private javax.swing.JButton cmdCancel4;
    private javax.swing.JButton cmdNext;
    private javax.swing.JButton cmdNext2;
    private javax.swing.JButton cmdNext3;
    private javax.swing.JButton cmdSearch;
    private javax.swing.JTabbedPane customerTabbedPane;
    private javax.swing.JTable customerTable;
    private javax.swing.JPanel generalPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblFax;
    private javax.swing.JLabel lblID;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblNotes;
    private javax.swing.JLabel lblPhone2;
    private javax.swing.JLabel lblPriContact;
    private javax.swing.JLabel lblPrimaryPhone;
    private javax.swing.JLabel lblSearch;
    private javax.swing.JLabel lblSecContact;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JPanel telephonePanel;
    private javax.swing.JTextArea txtAddress;
    private javax.swing.JTextField txtContact1;
    private javax.swing.JTextField txtContact2;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFax;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextArea txtNotes;
    private javax.swing.JTextField txtPhone1;
    private javax.swing.JTextField txtPhone2;
    private javax.swing.JTextField txtSearch;
    // End of variables declaration//GEN-END:variables
}
